import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class UrlLaunchPage extends StatefulWidget {
  @override
  _UrlLaunchPageState createState() => _UrlLaunchPageState();
}

class _UrlLaunchPageState extends State<UrlLaunchPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("打开浏览器和拨打电话"),
      ),
      body: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            RaisedButton(
                child: Text("打开外部浏览器"),
                onPressed: () async {
                  const url = 'https://cflutter.com';
                  if (await canLaunch(url)) {
                    await launch(url);
                  } else {
                    throw 'Could not launch $url';
                  }
                }),
                RaisedButton(
                child: Text("拨打电话"),
                onPressed: () async {
                  const tel = 'tel:10086';
                  if (await canLaunch(tel)) {
                    await launch(tel);
                  } else {
                    throw 'Could not launch $tel';
                  }
                }),
               RaisedButton(
                child: Text("发送短信"),
                onPressed: () async {
                  const tel = 'sms:10086';
                  if (await canLaunch(tel)) {
                    await launch(tel);
                  } else {
                    throw 'Could not launch $tel';
                  }
                }),
              RaisedButton(
                child: Text("打开外部应用"),
                onPressed: () async {
                  // weixin://
                  const app = 'alipays://';
                  if (await canLaunch(app)) {
                    await launch(app);
                  } else {
                    throw 'Could not launch $app';
                  }
                })
          ],
        ),
      ),
    );
  }
}
